﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Airplane : MonoBehaviour
{
    public float moveLRSpeed;
    public float moveFBSpeed;
    public float rotaLRSpeed;
    public float rotaUDSpeed;
    public FlightController flightController;
    public Rigidbody rBody;
    public FlightAgent agent;

    void Awake()
    {
        rBody = GetComponent<Rigidbody>();
        flightController = new FlightController();
        flightController.Initialize(this);
        agent = transform.parent.GetComponent<FlightAgent>();
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.CompareTag("BadSphere"))
        {
            agent.AddReward(-1);
            if((bool)agent.envCtrler.epm.GetPara(EP.isCrashEndEpisode))
                agent.OnEpisodeEnd();
            //Debug.Log("You collided with the BadSphere.");
        }

        if(collision.collider.CompareTag("Target"))
        {
            agent.AddReward(1);
            agent.OnEpisodeEnd();
            //agent.gameObject.SetActive(false);

            Debug.Log("I Reached the target!");
        }
    }
}
